<?php
	session_start();
	if (!isset($_SESSION["loginid"])) {
		echo "<script language='javascript'>";
		echo "alert('You have no permission!!');";
		echo "location.href = 'login.php';";
		echo "</script>";
	}else {
		require APP_DIR.'/host_config.php';
		require Controllers_DIR.'index_controller.php';
		$loginid = $_SESSION["loginid"];
		$shopid = $_SESSION["shopid"];
		$user = new Index_Controller();
		$open = $user->getShopStatus($shopid);
?>
<!DOCTYPE html>
<html lang="zh-tw">
	<head>
		<meta charset="utf-8">
		<title>WayWayNoWait - Management System</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<link href="<?php echo CSS_DIR.'bootstrap.min.css'?>" rel="stylesheet">
		<link href="<?php echo CSS_DIR.'main2.css'?>" rel="stylesheet">
		<style type="text/css">
			body {
				padding-top: 60px;
				padding-bottom: 40px;
				font-size: 16px;
			}
			button {
				margin-right: 5px;
				margin-left: 5px;
			}
			.nav-header {
				font-size: 30px;
				line-height: 30px;
			}
			.nav-header span {
				vertical-align: bottom;
			}
			.feature-nav {
				padding: 15px;
				height: 430px;
			}
			.info-nav {
				margin: 0;
				padding: 15px;
				height: 150px;
			}
			#profile {
				
			}
			#order {

				margin: 0 auto;
			}
			.tab-content {
				height: 600px;
				
			}
		</style>
		<link href="<?php echo CSS_DIR.'bootstrap-responsive.min.css'?>" rel="stylesheet">		
	</head>
	<body>
		<div class="navbar navbar-inverse navbar-fixed-top">
      		<div class="navbar-inner">
        		<div class="container-fluid">
          			<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            			<span class="icon-bar"></span>
            			<span class="icon-bar"></span>
            			<span class="icon-bar"></span>
          			</button>
          			<a class="brand" href="#"><?php echo $user->getShopName($loginid);?></a>
          			<div class="nav-collapse collapse">
            			<p class="navbar-text pull-right">
              				Logged in as <a href="#" class="navbar-link">Username</a>
            			</p>
            			<ul class="nav">
              				<li class="active"><a href="#">Home</a></li>
              				<li><a href="#about">About</a></li>
              				<li><a href="#contact">Contact</a></li>
            			</ul>	
          			</div><!--/.nav-collapse -->
        		</div>
      		</div>
    	</div>
    	<div class="container-fluid">
    		<div class="row-fluid">
    			<div class="span2">
    				<div class="well feature-nav">
	    				<ul class="nav nav-list" id="feature-tab">
	    					<li class="nav-header">
	    						<div>功能
	    						<button type="button" id="switch-btn" class="btn <?php echo ($open==1)?"btn-success":"btn-danger"?>"><?php echo ($open == 1)?"開店中":"關店中"?></button>
	    						</div><hr></li>
	    					<li><a href="#order"><span class="text">餐廳訂位資訊</span></a></li>
	    					<li><a href="#profile"><span class="text">餐廳資料修改</span></a></li>
	    				</ul>
    				</div><!--/.well-->
    				<div class="well info-nav">
	    				<ul class="nav nav-list">
	    					<li class="nav-header">訂位資訊<hr></li>
	    					<li>最大訂位人數：<span id="maxOrderNum"><?php echo $user->getMaxNumber($loginid);?></span></li>
	    					<li>目前訂位人數：<span id="currentOrderNum"><?php echo $user->getCurrentNumber($loginid);?></span></li>
	    				</ul>
    				</div><!--/.well-->
    			</div><!--/.span3-->
    			<div class="span10">
    				<div class="tab-content">
    					 <div class="tab-pane active" id="order"></div>
    					 <div class="tab-pane well" id="profile"></div>
    				</div>
    			</div><!--/.span9-->
    		</div><!--/.row-fluid-->
<!--
    	<footer>
    		<p>&copy; Company 2013</p>
    	</footer>
-->
    	</div><!--/.container-fluid-->


		<!-- JS -->
		<!--
		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
	-->
		<script src="<?php echo LIB_DIR.'jquery-1.10.2.min.js'?>"></script>
		<script src="<?php echo LIB_DIR.'jquery-ui-1.10.3.custom.min'?>"></script>
		<script src="<?php echo LIB_DIR.'bootstrap.min.js'?>"></script>
		<script src="<?php echo LIB_DIR.'main.js'?>"></script>
		<script>
			var open = <?php echo ($open == 1)?"\"on\"":"\"off\""?>;

			
			if(open == "on") {
				getShopState(60000);	
			}
			

	    	$('#feature-tab a').click(function (e) {
    			e.preventDefault();
    			$(this).tab('show');
    		})

			$(function() {
				$('#feature-tab a').on('shown', function(e){
					console.log(e.target.href);
					//console.log(e.relatedTarget.href);					
				});
				$('#feature-tab a').on('show', function(e){
					switch($(e.target).attr('href')) {
						case '#profile':
							$.get('/page', {page: 'shopInfo'}, function(response){
								$('div#profile').html(response);
							});break;
						case '#order':
							$.get('/page', {page: 'showOrderInfo'}, function(response){
								$('div#order').html(response);
							});break;
					}
				});
				$('#switch-btn').click(function(e) {
					var flag = (open == "on")?"off":"on";

					shopSwitch(flag, function(response) {
						if(response.result == "success") {
							open = flag;
							$(e.target).text((open == "on")?"開店中":"關店中");
							if((open == "on")) {
								$(e.target).removeClass('btn-danger').addClass('btn-success');
							}else {
								$(e.target).removeClass('btn-success').addClass('btn-danger');
							}
						}else {
							console.log(response.message);
							// alert fail message
							return false;

						}
					});
				});
				/*
				$('#switch-btn').click(function() {
					if($('switch-btn').hasClass('disabled')) {
						console.log("disabled");
					}
				    if($(this).attr('class-toggle') != undefined && !$(this).prop('disabled')){				            
				        if($(this).hasClass('active')) {
				        	
				        	//$.post('/user?action=shopswitch', {switch: "off"}, function(response) {
				        		if(response.result == "success") 
				        	}, "json");
				            $(this).removeClass($(this).attr('class-toggle'));

				        } else {
				            $(this).addClass($(this).attr('class-toggle'));
				        }
					}
      			});				
				*/
			})
		</script>
	</body>
</html>	
<?php		
	}
?>